package com.exercise;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class exercise02 {
    public static void main(String[] args) {
        Collection numList = new ArrayList();
        numList.add(88.5);
        numList.add(39.2);
        numList.add(77.1);
        numList.add(56.8);
        numList.add(89);
        numList.add(99);
        numList.add(59.5);

        System.out.println("------使用增强for遍历所有元素，并打印----------");
        for (Object n : numList){
            System.out.println(n);
        }
        System.out.println("------使用增强for遍历所有元素，打印不及格的分数；----------");
        for (Object n : numList){
            Double dNum = Double.parseDouble(n.toString());
            if(dNum < 60) System.out.println(dNum);
        }
        System.out.println("------使用增强for遍历所有元素，计算不及格的分数的数量，和平均分，并打印计算结果。----------");
        int unPassCount = 0;
        double totalScore = 0;
        Double size = Double.valueOf(numList.size());
        for (Object n : numList){
            double dNum = Double.parseDouble(n.toString());
            totalScore += dNum;
            if(dNum < 60) unPassCount++;
        }
        System.out.println("不及格的分数的数量为" + unPassCount + "，平均分为" + Math.round(totalScore / size  * 100) / 100.0);
        System.out.println("------使用增强for遍历所有元素，求出最高分，并打印；----------");
        double maxNumber = 0;
        for (Object n : numList){
            double dNum = Double.parseDouble(n.toString());
            if(dNum > maxNumber) maxNumber = dNum;
        }
        System.out.println("最高分为：" + maxNumber);
    }
}
